package cn.jeeweb.web.modules.sys.service.impl;

import cn.jeeweb.common.mybatis.mvc.service.impl.CommonServiceImpl;
import cn.jeeweb.common.mybatis.mvc.wrapper.EntityWrapper;
import cn.jeeweb.common.utils.StringUtils;
import cn.jeeweb.web.modules.sys.entity.User;
import cn.jeeweb.web.modules.sys.mapper.oracle.UserMapper;
import cn.jeeweb.web.modules.sys.service.IBCWUserService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Transactional
@Service("bcwUserService")
public class BCWUserServiceImpl extends CommonServiceImpl<UserMapper, User> implements IBCWUserService {

	@Override
	public User findByUsername(String username) {
		if (StringUtils.isEmpty(username)) {
			return null;
		}
		return selectOne(new EntityWrapper<User>(User.class)
				.setSqlSelect("USER_NAME as username, ENCRYPTED_USER_PASSWORD as password").eq("USER_NAME", username));
	}

	@Override
	public User findByEmail(String email) {
		if (StringUtils.isEmpty(email)) {
			return null;
		}
		return selectOne(new EntityWrapper<User>(User.class)
				.setSqlSelect("USER_NAME as username, ENCRYPTED_USER_PASSWORD as password").eq("EMAIL", email));
	}

	@Override
	public User findByPhone(String phone) {
		if (StringUtils.isEmpty(phone)) {
			return null;
		}
		return selectOne(new EntityWrapper<User>(User.class)
				.setSqlSelect("USER_NAME as username, ENCRYPTED_USER_PASSWORD as password").eq("MOBILE_PHONE", phone));
	}

}
